package com.xbts.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xbts.common.annotation.Log;
import com.xbts.common.core.controller.BaseController;
import com.xbts.common.core.domain.AjaxResult;
import com.xbts.common.enums.BusinessType;
import com.xbts.system.domain.CnNewsType;
import com.xbts.system.service.ICnNewsTypeService;
import com.xbts.common.utils.poi.ExcelUtil;
import com.xbts.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * 新闻类型Controller
 * @author xbts
 * @date 2023-09-05
 */
@Api("新闻类型")
@RestController
@RequestMapping("/system/news/type")
public class CnNewsTypeController extends BaseController {

    @Autowired
    private ICnNewsTypeService cnNewsTypeService;

    /**
     * 查询新闻类型列表
     */
    @ApiOperation("查询新闻类型列表")
    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody CnNewsType cnNewsType) {
        startPage(cnNewsType);
        List<CnNewsType> list = cnNewsTypeService.selectCnNewsTypeList(cnNewsType);
        return getDataTable(list);
    }

    /**
     * 导出新闻类型列表
     */
    @ApiOperation("导出新闻类型列表")
    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "新闻类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,@RequestBody CnNewsType cnNewsType) {
        List<CnNewsType> list = cnNewsTypeService.selectCnNewsTypeList(cnNewsType);
        ExcelUtil<CnNewsType> util = new ExcelUtil<CnNewsType>(CnNewsType.class);
        util.exportExcel(response, list, "新闻类型数据");
    }

    /**
     * 获取新闻类型详细信息
     */
    @ApiOperation("获取新闻类型详细信息")
    @ApiImplicitParam(name = "newsTypeId", value = "新闻类型ID", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{newsTypeId}")
    public AjaxResult getInfo(@PathVariable("newsTypeId") String newsTypeId) {
        return success(cnNewsTypeService.selectCnNewsTypeByNewsTypeId(newsTypeId));
    }

    /**
     * 新增新闻类型
     */
    @ApiOperation("新增新闻类型")
    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "新闻类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody CnNewsType cnNewsType) {
        return toAjax(cnNewsTypeService.insertCnNewsType(cnNewsType));
    }

    /**
     * 修改新闻类型
     */
    @ApiOperation("修改新闻类型")
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "新闻类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody CnNewsType cnNewsType) {
        return toAjax(cnNewsTypeService.updateCnNewsType(cnNewsType));
    }

    /**
     * 删除新闻类型
     */
    @ApiOperation("删除新闻类型")
    @ApiImplicitParam(name = "newsTypeIds", value = "新闻类型ID集合", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "新闻类型", businessType = BusinessType.DELETE)
	@PostMapping("/batchDelete")
    public AjaxResult batchDelete(@RequestBody List<String> newsTypeIds) {
        return toAjax(cnNewsTypeService.deleteCnNewsTypeByNewsTypeIds(newsTypeIds));
    }
}
